package com.syn.synold4s.control;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.core.content.ContextCompat;

import com.gaoyi.basemodule.baseControl.BaseView;
import com.gaoyi.basemodule.baseUtil.DateFormatUtil;
import com.syn.synold4s.R;
import com.syn.synold4s.databinding.MapItemBinding;
import com.syn.synold4s.databinding.TrackingViewBinding;

import java.util.Date;

public class TrackingView extends BaseView<TrackingViewBinding> {

    public TrackingView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void initView(TypedArray ta) {
        // 底部文本
        String title = ta.getString(R.styleable.TrackingView_tracking_title);
        int bgId = ta.getResourceId(R.styleable.TrackingView_tracking_bg_src, R.drawable.oval_green);
        int color = ta.getColor(R.styleable.TrackingView_tracking_num_color, ContextCompat.getColor(mContext, R.color.green));
        mBinding.tvTrackingTitle.setText(title);
        mBinding.tvTrackingNum.setBackgroundResource(bgId);
        mBinding.tvTrackingNum.setTextColor(color);
    }

    /**
     * 上方数量
     */
    public void setNum(int num) {
        mBinding.tvTrackingNum.setText(String.valueOf(num));
    }

    /**
     * 上方数量
     */
    public void setTime(Date time) {
        mBinding.tvTrackingTime.setText(DateFormatUtil.DateTimeToStr(time, "dd-MM-YYYY HH:mm:ss"));
    }

    public void setNumAndTime(int num, Date time) {
        setNum(num);
        setTime(time);
    }

    @Override
    protected TrackingViewBinding getViewBinding() {
        return TrackingViewBinding.inflate(LayoutInflater.from(mContext));
    }

    @Override
    protected int[] getAttrs() {
        return R.styleable.TrackingView;
    }
}
